Developer Documentation
PATHJava Developer Documentation > Mac OS Runtime for Java > JManager > Programming With JManager


Java Sessions, AWT Contexts, and Frames

To run Java applets on the Mac OS platform, you must first create a Java runtime session , which is an instantiation of the Java runtime environment. This environment can then load and execute Java code. Figure 1-2 shows an instantiated Java session and elements associated with it.

Figure 1-2 An instantiated Java session

Within a session, a Java applet must run within an Abstract Window Toolkit (AWT) context. The AWT context provides an execution environment and a thread group for the Java program. Each Java applet must have its own AWT context. However, a given session can contain multiple contexts, each of which runs independently.

In addition to providing an execution environment, the AWT context allows access to the Abstract Window Toolkit. Java programs that display any graphical information (such as a text window, a button, or an image) must do so by calling the AWT. A call to the AWT manipulates images in a virtual window called a frame. This action is analogous to a Mac OS program calling the Mac OS Toolbox to manipulate images in a user-visible screen window.

To make the contents of a frame visible to the user, JManager cooperates with the AWT to pass information between the Java program and the Mac OS. For example, if the Java program decides to open a window, it tells the AWT, which can then call the appropriate Mac OS Toolbox functions to display a new window. Similarly, if the user selects a button, the selection is passed back to the Java program through the AWT. Figure 1-3 compares the elements needed by Mac OS code and Java code to display graphical information in a Mac OS window.

Figure 1-3 Frames versus windows

A Java applet can have any number of frames. A frame does not necessarily have to correspond to a visible Mac OS window. For example, you could assign a frame to a graphics port that displays data on a pen plotter instead of a window.

Since the Java runtime environment is object-oriented, each element associated with it is defined by an object. For example, an AWT context is defined by the JMAWTContextRef object, and the Java session itself is defined by an object of type JMSessionRef . Creating any element (for example, a frame) involves instantiating an instance of that object type.

To run a Java applet on the Mac OS, you must do the following:

  1. Create the Java runtime environment.
  2. Find the applet.
  3. Create an AWT context.
  4. Instantiate the applet.

IMPORTANT

To support inline input into Java text areas and text fields, your embedding application must be Text Services Manager-aware. For TSM-aware applications, when focus passes to a Java text field that accepts inline input, MRJ automatically makes the field the active TSM document and installs the proper Apple Event handlers. See Inside Macintosh: Text for more information about using the Text Services Manager.


© 1998 Apple Computer, Inc. — (Last Updated 3 Dec 98)